package com.gd.service.impl;

import com.gd.dao.UserDao;
import com.gd.pojo.User;
import com.gd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired

    private UserDao userDao;


    @Override
    public User checkLogin(String username, String password) {
        /**
         * 通过用户名查出用户名和密码数据库返回User用户账户名密码
         */
        User login = userDao.findByUsername(username);
        /**
         * 判断是否存在用户,如果不存在直接null如果存在继续验证表单传给service的密码是否一样
         */
        if (login != null && login.getPassword().equals(password))
            return login;
        else
            return null;
    }


    @Override
    public void Regist(User user) {
        userDao.registerByUsernameAndPassword(user.getUsername(),user.getPassword());
    }
}
